package rpc.frame.core.netty.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import rpc.frame.core.data.RpcResponse;
import rpc.frame.core.handler.RpcRequestHandler;
import rpc.frame.core.request.RequestPromise;
import rpc.frame.core.request.RpcRequestHolder;

@ChannelHandler.Sharable
@Slf4j
public class RpcResponseHandler  extends SimpleChannelInboundHandler<RpcResponse> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, RpcResponse rpcResponse) throws Exception {
        RequestPromise requestPromise = RpcRequestHolder.getRequestPromise(rpcResponse.getRequestId());
        if (requestPromise!=null) {
            requestPromise.setSuccess(rpcResponse);
        }
    }
}
